//
//  MeService.m
//  HxgProject
//
//  Created by hxg on 2018/3/27.
//  Copyright © 2018年 XMYY-19. All rights reserved.
//

#import "MeService.h"
#import "NetworkManager.h"
#import "HxgInterfaceDefine.h"
#import "ReferencesInfo.h"
#import "PackageDetailInfo.h"

#import "ResObject.h"

@implementation MeService

- (void)getPackageDetailWithCallBack:(void(^)(NSMutableArray *returnArr)) callBack
{
    NetworkManager *man = [NetworkManager sharedNetworkManager];
    NSString *urlInfo = [NSString stringWithFormat:@"%@%@",iP_Address,JK_EDu_kGetPackageInfo];
    //2.封装参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"phone"] = [[NSUserDefaults standardUserDefaults] objectForKey:kPhoneNum];
    
    [man getURL:urlInfo parameters:params success:^(id responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        
        NSMutableArray *allApplyInfos = [[NSMutableArray alloc] init];
        NSArray *arr = [responseObject objectForKey:@"paymentDetail"];
        if ([responseObject objectForKey:@"paymentDetail"] != [NSNull null]
            && nil != arr
            && 0 != arr.count
            )
        {
            for (NSDictionary *dic in arr)
            {
                PackageDetailInfo *packageDetailInfo = [[PackageDetailInfo alloc] initWithDic:dic];
                [allApplyInfos addObject:packageDetailInfo];
            }
        }
        
        callBack(allApplyInfos);
    } failure:^(NSError *error, ParamtersJudgeCode judgeCode) {
        NSLog(@"judgeCode===>%lu",(unsigned long)judgeCode);
        callBack(nil);
    }];
}

- (void)getBasicInformation:(void(^)(NSMutableDictionary *returnDic)) callBack
{
    NetworkManager *man = [NetworkManager sharedNetworkManager];
    NSString *urlInfo = [NSString stringWithFormat:@"%@%@",iP_Address,JK_Basic_kFindBasicInformation];
    //2.封装参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    // id:""//数据库配置信息查询 1.查询套餐信息 2.查询QQ提示信息
    params[@"id"] = @"2";
    
    [man getURL:urlInfo parameters:params success:^(id responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        
        callBack(nil);
    } failure:^(NSError *error, ParamtersJudgeCode judgeCode) {
        NSLog(@"judgeCode===>%lu",(unsigned long)judgeCode);
        callBack(nil);
    }];
}

- (void)savereferencesInfo:(ReferencesInfo *)referencesInfo
              withCallBack:(void(^)(BOOL isSucc)) callBack
{
    NetworkManager *man = [NetworkManager sharedNetworkManager];
    NSString *urlInfo = [NSString stringWithFormat:@"%@%@",iP_Address,JK_Other_kSavereferencesInfo];
    //2.封装参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    params[@"phone"] = [[NSUserDefaults standardUserDefaults] objectForKey:kPhoneNum];
    params[@"parentId"] = referencesInfo.parentId;
    params[@"id"] = referencesInfo.currentId;
    
    [man postURL:urlInfo parameters:params success:^(id responseObject) {
        NSLog(@"xin yu ==>responseObject:%@",responseObject);
        if ([[responseObject objectForKey:@"Success"]  isEqual: @(YES)])
        {
            callBack(YES);
        } else {
            callBack(NO);
        }
    } failure:^(NSError *error, ParamtersJudgeCode judgeCode) {
        NSLog(@"judgeCode===>%lu",(unsigned long)judgeCode);
        callBack(NO);
    }];
}

- (void)getReferencesInfoWithCallback:(void(^)(ReferencesInfo *referencesInfo)) callBack
{
    NetworkManager *man = [NetworkManager sharedNetworkManager];
    NSString *urlInfo = [NSString stringWithFormat:@"%@%@",iP_Address,JK_Other_kGeteferencesInfo];
    //2.封装参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    // id:""//数据库配置信息查询 1.查询套餐信息 2.查询QQ提示信息
    params[@"phone"] = [[NSUserDefaults standardUserDefaults] objectForKey:kPhoneNum];
    
    [man getURL:urlInfo parameters:params success:^(id responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        ReferencesInfo *referencesInfo = [[ReferencesInfo alloc] initWithDic:responseObject];
        callBack(referencesInfo);
    } failure:^(NSError *error, ParamtersJudgeCode judgeCode) {
        NSLog(@"judgeCode===>%lu",(unsigned long)judgeCode);
        callBack(nil);
    }];
}

- (void)getOnlineServicerWithCallBack:(void(^)(NSString *onLineInfo))callback
{
    NetworkManager *man = [NetworkManager sharedNetworkManager];
    NSString *urlInfo = [NSString stringWithFormat:@"%@%@",iP_Address,JK_Basic_kFindBasicInformation];
    //2.封装参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"phone"] = [[NSUserDefaults standardUserDefaults] objectForKey:kPhoneNum];
    params[@"name"] = kBasicInfoOnLiner;
    
    [man getURL:urlInfo parameters:params success:^(id responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        
        NSDictionary *responDic = (NSDictionary *)responseObject;
        NSArray *arr = responDic[@"BasicInformationList"];
        if (arr
            && arr.count != 0) {
            NSDictionary *dic = arr[0];
            if (isEmptyString(dic[@"detailedInstructions"])) {
                callback(@"请加QQ：415745067");
            } else {
                callback(dic[@"detailedInstructions"]);
            }
        } else {
            callback(@"请加QQ：415745067");
        }
    } failure:^(NSError *error, ParamtersJudgeCode judgeCode) {
        callback(@"请加QQ：415745067");
    }];
}

@end
